package interview;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class interview_16_20 {
    public List<String> getValidT9Words(String num, String[] words) {
        List<int[]> list=new ArrayList<>();
        list.add(new int[]{0,3});
        list.add(new int[]{3,3});
        list.add(new int[]{6,3});
        list.add(new int[]{9,3});
        list.add(new int[]{12,3});
        list.add(new int[]{15,4});
        list.add(new int[]{19,3});
        list.add(new int[]{22,4});
        List<String> result=new LinkedList<>();
        for(int i=0;i< words.length;++i){
            boolean flag=true;
            for(int j=0;j<num.length();++j){
                int[] tmp=list.get(num.charAt(j)-'2');
                if(words[i].charAt(j)-'a'>=tmp[0]&&words[i].charAt(j)-'a'<tmp[0]+tmp[1]){

                }else{
                    flag=false;
                    break;
                }
            }
            if(flag){
                result.add(words[i]);
            }
        }
        return result;
    }
}
